package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import utiles.LogUtil;

public class MainActivity extends AppCompatActivity {

    private TextView mTextView1;
    private TextView mTextView2;
    private TextView mTextView3;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;//hello world
        });
        mTextView1 = findViewById(R.id.tiaozhuan);
        mTextView2 = findViewById(R.id.textview1);
        mTextView3 = findViewById(R.id.textview2);


        mTextView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("test111", "=====mTextView1 onClick======");
                onTextViewClick(1);
                //Intent intent =new Intent(MainActivity.this,secondActivity.class);
                //startActivity(intent);
            }
        });
        mTextView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LogUtil.d("test111","---mtextview2 onClick---");
                onTextViewClick(2);
            }
        });
        mTextView3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, "嗨嗨嗨。泥蝶来喽", Toast.LENGTH_SHORT).show();
            }
        });


    }
    private void onTextViewClick(int i){
        LogUtil.d("test111","----onTestViewClick---"+i);
        if (i==1){
            showToast("TextView 1 Click");
        } else if (i==2) {
            showActivity();
        }
        ;
    };
    private void showToast(String text){
        LogUtil.d("test111","---showToast---"+ text);
        Toast.makeText(this,"456",Toast.LENGTH_LONG).show();
    };
    private void showActivity(){
        LogUtil.d("test111", "=====showActivity======");
        Intent intent = new Intent(MainActivity.this, secondActivity.class);
        startActivity(intent);
    };
}